<template>
  <div class="dashboard-container">
    <h1 style="text-align: center">日志</h1>

    <el-input
      v-model="systemLogId"
      placeholder="日志ID"
      name="systemLogId"
      type="text"
      clearable
      style="margin-left:17% ;width: 180px"
    />
    <el-input
      v-model="userId"
      placeholder="用户ID"
      name="userId"
      type="text"
      clearable
      style="margin-left:40px ;width: 180px"
    />

    <el-select
      v-model="roleName"
      clearable placeholder="请选择角色"
      style="margin-left:40px ;width: 180px">
      <el-option
        v-for="item in roleNames"
        :key="item.roleName"
        :label="item.roleName"
        :value="item.roleName"/>
    </el-select>

    <el-button plain
               style="width:80px;margin-bottom:30px;margin-left:40px ;background-color: #cfefc6; border-radius: 8px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);"
               @click="selectAll"
    >
      查询
    </el-button>
    <el-button
      style="width:80px;margin-bottom:30px;margin-left:40px ;background-color: white; border-radius: 8px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);"
      @click="checkSystemLog"
    >重置
    </el-button>
    <el-table :data="systemLogList.slice((currentPage-1)*pagesize,currentPage*pagesize)" height="630px" border style="width: 100%;margin-top: 20px"
              class="elegant-room-table"
    >
      <el-table-column align="center" fixed prop="systemLogId" label="日志ID" min-width="100"/>
      <el-table-column align="center" fixed prop="userId" label="用户ID" width="100"/>
      <el-table-column align="center" fixed prop="roleName" label="用户角色" min-width="100"/>
      <el-table-column align="center" fixed prop="createTime" label="操作时间" min-width="100"/>
      <el-table-column align="center" fixed prop="useTableName" label="操作表名" width="110"/>
      <el-table-column align="center" fixed prop="useTableDataIdBefore" label="操作前数据" width="110"/>
      <el-table-column align="center" fixed prop="useTableDataIdAfter" label="操作后数据" min-width="110"/>
      <el-table-column align="center" fixed prop="useType" label="操作类型" width="120"/>
    </el-table>

    <div style="margin-top:5px;margin-left: 30%;">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5,8,10,12,15,20]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="systemLogList.length">
      </el-pagination>
    </div>

  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { deleteRoomType, insert1RoomType, selectAllRoomType, updateRoomType } from '@/api/roomType'
import { insertCustomer, selectAllCustomer, updateCustomer } from '@/api/customer'
import { selectAllLiveRecords } from '@/api/liveRecords'
import { abrogateStay1, cancelStay, insertStay, selectAllStay1 } from '@/api/stay'
import { collectionLive1, selectAllLive, settlementLive1 } from '@/api/live'
import { selectAllSystemLog } from '@/api/systemLog'

export default {
  name: 'user',
  computed: {
    ...mapGetters([
      'userId',
      'userName',
      'roleName'
    ])
  },
  data() {
    return {
      systemLogId: '',
      userId: '',
      roleName: '',
      systemLogList: [],
      roleNames:[],
      currentPage: 1,
      currentIndex: '',
      pagesize: 12,
    }
  },
  mounted() {
    this.selectAll()
    this.fetchSystemLog()
  },
  methods: {
    handleSizeChange(val) {
      this.pagesize = val;
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.currentPage= val
    },

    selectAll() {
      selectAllSystemLog({
        systemLogId:this.systemLogId,
        userId:this.userId,
        roleName:this.roleName
      }).then(
        response => {
          console.log(response.data)
          this.systemLogList = response.data
        }
      )
    },
    // 下拉
    fetchSystemLog() {
      selectAllSystemLog().then(response => {
        this.roleNames = Object.values(
          response.data.reduce((selectRoleName, item) => {
            selectRoleName[item.roleName] = item
            return selectRoleName
          }, {})
        )
      })
    },
    checkSystemLog(){
      this.systemLogId = ''
      this.userId = ''
      this.roleName = ''
      this.selectAll()
    },
  }
}
</script>

<style lang="scss" scoped>
.dashboard {
  &-container {
    margin: 30px;
  }

  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}

.elegant-room-table {
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  box-shadow: 0 4px 12px 0 rgba(0, 0, 0, 0.05);
  border-radius: 8px;
  overflow: hidden;

  &::before {
    display: none;
  }

  .price-tag {
    display: inline-block;
    padding: 3px 8px;
    color: #171717;
    border-radius: 12px;
    font-weight: 500;
  }
}

.status-green {
  color: green;
}

.status-red {
  color: red;
}
</style>
